using System;
using System.Runtime.InteropServices;

namespace Fireball.ArchLinux.Pacman
{		
	///<summary>
	/// Functions to query and manipulate the database of libalpm.
	///</summary>
	public class DatabaseApi
	{
        /// <summary>
        /// Register a package database
        /// </summary>
        /// <param name="treename">The name of the repository</param>
        /// <returns>A pmdb_t* on success (the value), NULL on error</returns>
		[DllImport("libalpm")]
		public extern static IntPtr alpm_db_register(string treename);	
		
        /// <summary>
        /// Unregister a package database
        /// </summary>
        /// <param name="db">Pointer to the package database to unregister</param>
        /// <returns>0 on success, -1 on error (pm_errno is set accordingly)</returns>		
		[DllImport("libalpm")]
		public extern static int alpm_db_unregister(IntPtr db);			

	    /// <summary>
	    /// Set the serverlist of a database.
	    /// </summary>
	    /// <param name="db">Database pointer</param>
	    /// <param name="url">Url of the server</param>
        /// <returns>Set the serverlist of a database.</returns>
		[DllImport("libalpm")]
		public extern static int alpm_db_setserver(IntPtr db,string url);	
		
		/// <summary>
		/// Update a package database
		/// </summary>
		/// <param name="force">If true, then forces the update, otherwise update only in
        ///   case the database isn't up to date</param>
		/// <param name="db">Pointer to the package database to update</param>
        /// <returns>0 on success, > 0 on error (pm_errno is set accordingly), < 0 if up to date</returns>		
		[DllImport("libalpm")]
		public extern static int alpm_db_update(int force,IntPtr db);	
		
		/// <summary>
		/// Get a package entry from a package database
		/// </summary>
		/// <param name="db">Pointer to the package database to get the package from</param>
		/// <param name="name">Name of the package</param>
        /// <returns>The package entry on success, NULL on error</returns>
		[DllImport("libalpm")]
		public extern static IntPtr alpm_db_get_pkg(IntPtr db,string name);		
		
		/// <summary>
		/// Get the package cache of a package database
		/// </summary>
		/// <param name="db">Pointer to the package database to get the group from</param>
        /// <returns>The list of packages on success, NULL on error</returns>		
		[DllImport("libalpm")]
		public extern static IntPtr alpm_db_getpkgcache(IntPtr db);
		
		/// <summary>
		/// Get the list of packages that a package provides
		/// </summary>
		/// <param name="db">Pointer to the package database to get the package from</param>
		/// <param name="name">Name of the package</param>
        /// <returns>The list of packages on success, NULL on error</returns>		
		[DllImport("libalpm")]
		public extern static IntPtr alpm_db_whatprovides(IntPtr db,string name);
		
		/// <summary>
		///  Get a group entry from a package database
		/// </summary>
		/// <param name="db">Pointer to the package database to get the group from</param>
		/// <param name="name">Name of the group</param>
        /// <returns>The groups entry on success, NULL on error</returns>			
		[DllImport("libalpm")]
		public extern static IntPtr alpm_db_readgrp(IntPtr db,string name);			
		
		/// <summary>
		/// Get the group cache of a package database
		/// </summary>
		/// <param name="db">Pointer to the package database to get the group from</param>
        /// <returns>The list of groups on success, NULL on error</returns>	
		[DllImport("libalpm")]
		public extern static IntPtr alpm_db_getgrpcache(IntPtr db,string name);		
	}
}
